#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <format>
using namespace std;
void outputCharArray(char arr[], int n) {
  cout << '[';
  for (int i = 0; i < n; i ++) {
    if (i) cout << ',';
    if (arr[i] == '\0') {
      cout << "\\0";
    } else {
      cout << arr[i];
    }
  }
  cout << ']' << endl;
}
int main () {
  // init
  cout << "### init" << endl;
  char str1[] = {'a', 'b', 'c', 'd'};
  cout << "char str[] = {'a', 'b', 'c', 'd'}; -> ";
  outputCharArray(str1, 4);
  char str2[] = "abcd";
  cout << "char str[] = \"abcd\";               -> ";
  outputCharArray(str2, 5);
  // input
  cout << endl << "### input" << endl;
  cout << "scanf(\"%s\", str2);" << endl;
  cout << "cin >> str2;" << endl;
  cout << "cin.getline(str2, 6);" << endl;
  cout << "fgets(str2, 6, stdin);" << endl;
  // func
  cout << endl << "### string.h" << endl;
  cout << format("{:25} -> {}", "strlen(\"abc\")", strlen("abc")) << endl;
  char str[10];
  strcpy(str, "123");
  cout << format("{:25} -> {}", "strcpy(str, \"123\")", strlen("abc")) << endl;
  strcat(str, "456");
  cout << format("{:25} -> {}", "strcat(str, \"456\")", str) << endl;
  cout << format("{:25} -> {}", "strcmp(\"abc\", \"abd\")", strcmp("abc", "abd")) << endl;
  cout << format("{:25} -> {}", "strcmp(\"abc\", \"abc\")", strcmp("abc", "abc")) << endl;
  cout << format("{:25} -> {}", "strcmp(\"abc\", \"abb\")", strcmp("abc", "abb")) << endl;
  cout << format("{:25} -> {}", "strstr(\"abcdef\", \"cde\")", strstr("abcdef", "cde")) << endl;
  if (strstr("abcdef", "cba") == NULL) {
    cout << format("{:25} -> {}", "strstr(\"abcdef\", \"cba\")", "NULL") << endl;
  }
  strcpy(str, "1+2-3*4/5");
  char* token = strtok(str, "+-*/");
  cout << format("{:25} -> {}", "strcpy(str, \"1+2-3*4/5\")", token) << endl;
  while (token) {
    token = strtok(NULL, "+-*/");
    if (token) {
      cout << format("{:25} -> {}", "strcpy(NULL, \"1+2-3*4/5\")", token) << endl;
    }
  }
  cout << format("{:25} -> ", "str after while strtok");
  outputCharArray(str, 9);
  memset(str, '?', 10);
  cout << format("{:25} -> ", "memset(str, '?', 10)");
  outputCharArray(str, 10);
  memcpy(str, "abcd", 2);
  cout << format("{:25} -> ", "memcpy(str, \"abcd\", 2)");
  outputCharArray(str, 10);
  int intArr[1];
  memset(intArr, 1, 4);
  cout << format("{:25} -> {}", "memset(intArr, 1, 4)", intArr[0]) << endl;

  cout << endl << "### stdlib.h" << endl;
  cout << format("{:25} -> {}", "atoi(\"123\")", atoi("123")) << endl;
  cout << format("{:25} -> {}", "atoll(\"12345678901\")", atoll("12345678901")) << endl;
  cout << format("{:25} -> {}", "atof(\"1e9\")", atof("0.1")) << endl;

  cout << endl << "### ctype.h" << endl;
  cout << format("{:15} -> {}", "isprint(' ')", (bool)isprint(' ')) << endl;
  cout << format("{:15} -> {}", "isprint(31)", (bool)isprint(31)) << endl;
  cout << format("{:15} -> {}", "isspace(' ')", (bool)isspace(' ')) << endl;
  cout << format("{:15} -> {}", "isspace('a')", (bool)isspace('a')) << endl;
  cout << format("{:15} -> {}", "isgraph('a')", (bool)isgraph('a')) << endl;
  cout << format("{:15} -> {}", "isgraph(' ')", (bool)isgraph(' ')) << endl;
  cout << format("{:15} -> {}", "ispunct('*')", (bool)ispunct('*')) << endl;
  cout << format("{:15} -> {}", "ispunct('a')", (bool)ispunct('a')) << endl;
  cout << format("{:15} -> {}", "isalnum('0')", (bool)isalnum('0')) << endl;
  cout << format("{:15} -> {}", "isalnum('*')", (bool)isalnum('*')) << endl;
  cout << format("{:15} -> {}", "isdigit('0')", (bool)isdigit('0')) << endl;
  cout << format("{:15} -> {}", "isdigit('a')", (bool)isdigit('a')) << endl;
  cout << format("{:15} -> {}", "isupper('A')", (bool)isupper('A')) << endl;
  cout << format("{:15} -> {}", "isupper('a')", (bool)isupper('a')) << endl;
  cout << format("{:15} -> {}", "islower('a')", (bool)islower('a')) << endl;
  cout << format("{:15} -> {}", "islower('A')", (bool)islower('A')) << endl;
  cout << format("{:15} -> {}", "toupper('a')", (char)toupper('a')) << endl;
  cout << format("{:15} -> {}", "tolower('A')", (char)tolower('A')) << endl;
}